<?php
/**
 * 获取护理统计
 * @authors Hex
 * @date    2017-03-010 15:10:05
 * @version $Id$
 */

class ZhuyuanHuliTongjiModel extends BaseModel {

    public function getTongjiItemList()
    {
        return DB::select('id,tongji_item_code,tongji_item_name')
            ->from('data_hulitongji_item')
            ->where('is_include', '=', '是')
            ->where('yiyuan_id', '=', $this->yiyuan_id)
            ->order_by('extend2', 'ASC')
            ->execute()
            ->as_array();
    }

    public function getTongjiCishu($user_number,$start_date_time,$end_date_time,$tongji_item_code)
    {
        return DB::select('COUNT("*") as total')
            ->from('zhuyuan_hulitongji_jilu')
            ->where('hushi_id', '=', $user_number)
            ->where('record_time', '>=', $start_date_time)
            ->where('record_time', '<=', $end_date_time)
            ->where('tongji_item_id','=',$tongji_item_code)
            ->where('yiyuan_id','=',$this->yiyuan_id)
            ->execute()
            ->get("total", 0);
    }

    public function getTongjiSubList($user_number,$start_date_time,$end_date_time,$tongji_item_code)
    {
        return DB::select('tongji_item_name as item_name,count(id) as count')
            ->from('zhuyuan_hulitongji_jilu')
            ->where('hushi_id', '=', $user_number)
            ->where('record_time', '>=', $start_date_time)
            ->where('record_time', '<=', $end_date_time)
            ->where('tongji_item_id','=',$tongji_item_code)
            ->where('yiyuan_id','=',$this->yiyuan_id)
            ->group_by('tongji_item_name')
            ->execute()
            ->as_array();
    }
}
